package com.xcm.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xcm.dao.ProgramTopMapper;
import com.xcm.model.TbProgramTop;
import com.xcm.service.ProgramTopService;

/**
 * 上屏节目Service实现类
 */
@Service(value = "programTopService")
public class ProgramTopServiceImpl implements ProgramTopService {
	@Autowired
	private ProgramTopMapper programTopMapper;

	/**
	 * 通过xc版本查找上屏屏节目列表
	 *
	 * @param xcVersion xc版本
	 * @return
	 */
	@Override
	public List<TbProgramTop> listProgramTopByXcVersion(String xcVersion, String top) {
		top = top.replaceAll("\"","");  
		String [] tops = top.split(",");
		List<TbProgramTop> orders = new ArrayList<>();
		List<TbProgramTop> listProgramTopByXcVersion = programTopMapper.listProgramTopByXcVersion(xcVersion, Arrays.asList(tops));
		// 不去重排序
		TbProgramTop pro = null;
		for ( String str : tops ) {
			for (TbProgramTop tbProg: listProgramTopByXcVersion) {
				if ( str.equals(tbProg.getName()) ) {
					pro = tbProg;
					continue;
				}
			}
			orders.add(pro);
		}
		return orders;
	}
}
